package com.server.llh.llhserverwork.utils;


import com.server.llh.llhserverwork.bean.SerInitProPackage;

import java.util.ArrayList;

/**
 * 服务购物车相关逻辑处理
 * Created by ZTF on 2017/3/21.
 */

public class ShoppingServerCar {
    /**
     * 服务购物车相关逻辑处理
     * @param serInitProPackage
     * @param shopping_car_List
     * @return
     */
    public static int getShopingData(SerInitProPackage serInitProPackage, ArrayList<SerInitProPackage> shopping_car_List) {
        boolean isAdded = false;
        for (int i = 0; i < shopping_car_List.size(); i++) {
            SerInitProPackage tempFoodModel = shopping_car_List.get(i);
            if (serInitProPackage.packId == tempFoodModel.packId) {
                isAdded = true;
                if (serInitProPackage.buyNum <= 0) {
                    shopping_car_List.remove(i);
                    i--;
                }
                tempFoodModel.saleNums = serInitProPackage.saleNums;
                break;
            }
        }
        if (!isAdded && serInitProPackage != null) {
            boolean isAdded2 = false;
            for (int i = 0; i < shopping_car_List.size(); i++) {
                SerInitProPackage tempFoodModel = shopping_car_List.get(i);
                if (serInitProPackage.packId == tempFoodModel.packId) {
                    shopping_car_List.add(serInitProPackage);
                    isAdded2 = true;
                    break;
                }
            }
            if (!isAdded2) {
                shopping_car_List.add(serInitProPackage);
            }
        }
        int num = 0;
        for (int i = 0; i < shopping_car_List.size(); i++) {
            SerInitProPackage tempServerModel = shopping_car_List.get(i);
            num = num + tempServerModel.buyNum;

        }
        return num;
    }

}
